home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_12 / saks / shapes.cpp < prev   
Encoding:
C/C++ Source or Header  |  1993-10-10  |  756 b   |  36 lines

  1. Listing 7 - A simple application using shapes
  2.  
  3. const shape *largest(const shape *sa[], size_t n)
  4.     {
  5.     const shape *s = 0;
  6.     double m = 0;
  7.     for (size_t i = 0; i < n; ++i)
  8.         if (sa[i]->area() > m)
  9.             {
  10.             m = sa[i]->area();
  11.             s = sa[i];
  12.             }
  13.     return s;
  14.     }
  15.  
  16. int main()
  17.     {
  18.     const int N = 4;
  19.     const shape *s[N];
  20.     const shape *ls;
  21.     s[0] = new circle(shape::RED, 2);
  22.     s[1] = new rectangle(shape::BLUE, 5, 6));
  23.     s[2] = new rectangle(shape::RED, 3, 4);
  24.     s[3] = new circle(shape::GREEN, 3);
  25.     cout << "The shapes are:\n";
  26.     for (int i = 0; i < N; ++i)
  27.         cout << i << ")\t" << *s[i] << '\n';
  28.     cout << '\n';
  29.     ls = largest(s, N);
  30.     cout << "The shape with the largest area is a...\n\t";
  31.     cout << *ls << ".\n";
  32.     cout << "Its area is " << ls->area() << ".\n";
  33.     return 0;
  34.     }
  35.  
  36.